package com.mysqldemo.entity.query;

import com.mysqldemo.enums.PageSize;

public class SimplePage{
    private int pageNo;//当前页
    private Integer countTotal;//总记录数
    private int pageSize;//每页显示的记录数
    private int pageTotal;//总页数
    private int start;//开始记录数
    private int end;//结束记录数


    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getCountTotal() {
        return countTotal;
    }

    public void setCountTotal(Integer countTotal) {
        this.countTotal = countTotal;
        this.action();
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageTotal() {
        return pageTotal;
    }

    public void setPageTotal(int pageTotal) {
        this.pageTotal = pageTotal;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }



    public SimplePage(){
    }

    public SimplePage(Integer pageNo,Integer countTotal,int pageSize){
        if(null == pageNo){
            pageNo = 0;
        }
        this.pageNo=pageNo;
        this.countTotal=countTotal;
        this.pageSize=pageSize;
        action();
    }

    public SimplePage(int start,int end){
        this.start=start;
        this.end=end;
    }
     //计算开始记录数和结束记录数
    public void action(){
        if(this.pageSize<=0){
            this.pageSize = PageSize.SIZE20.getSize();
        }

        if(this.pageNo<=1){
            this.pageNo = 1;
        }
        if(this.countTotal>0){
            this.pageTotal = (int) (this.countTotal%this.pageSize==0?this.countTotal/this.pageSize:this.countTotal/this.pageSize+1);
        }else{
            this.pageTotal = 1;
        }
        if(pageNo<=1){
            pageNo = 1;
        }
        if(pageNo>=pageTotal){
            pageNo = pageTotal;
        }
        this.start = (pageNo-1)*pageSize;
        this.end = this.pageSize;
    }


}
